<?

#------------------------------------------------------------------------
#	Includes from Josh													
#------------------------------------------------------------------------
	
# Globals
$GloDefine_Function = "../includes/defines_global.php";
$UsDefine_Function = "../includes/defines_user.php";
$TblDefine_Function = "../includes/defines_tables.php";
if (file_exists($GloDefine_Function)){
	include($GloDefine_Function);
	include($UsDefine_Function);
	include($TblDefine_Function);
}else{
	include('../'. $GloDefine_Function);
	include('../'. $UsDefine_Function);
	include('../'. $TblDefine_Function);
}	

# Connection
$PDO_Function = 'includes/specs_pdo.php';
if (file_exists($PDO_Function))
	include($PDO_Function);
else
	include('../'. $PDO_Function);

# Table defines
$Defines_Function = 'includes/specs_defines_tables.php';
if (file_exists($Defines_Function))
	include($Defines_Function);
else
	include('../'. $Defines_Function);

# Functions
$File_Function = '../includes/functions.php';
if (file_exists($File_Function))
	include($File_Function);
else
	include('../'. $File_Function);

#Session	
$File_Function = '../session.php';
if (file_exists($File_Function))
	include($File_Function);
else
	include('../'. $File_Function);

#------------------------------------------------------------------------

function get_session($DB){
	$Session = new Session( $DB );
	$Session->Refresh();
	return $Session;
}

if(!function_exists('microtime_float')){
	function microtime_float() 
	{ 
		list ($msec, $sec) = explode(' ', microtime()); 
		$microtime = (float)$msec + (float)$sec; 
		return $microtime; 
	}
}

function get_options() {
	return array(
		1 => 'Not so great',
		2 => 'Quite good',
		3 => 'Good',
		4 => 'Great!',
		5 => 'Excellent!',
	);
}

function saveImage($encodedPNGData, $percent, $specId){

	$binaryData = base64_decode($encodedPNGData);
	$file = "../media/specImages/".$specId.".png";
	file_put_contents($file, $binaryData);
	
}

function getDB(){
	return (new Database(DB_DATABASE, DB_TABLE, DB_USER, DB_PASS));
}

function getOldDB(){
	return (new Database("lafilch.mysql.db.hostpoint.ch", "lafilch_ffxivcalc", "lafilch_pads", "pads23"));
}

function leaveDB($db){
	$db->Disconnect();
}

function printGoogleAnalytics(){


	return "<script type=\"text/javascript\">

			  var _gaq = _gaq || [];
			  _gaq.push(['_setAccount', 'UA-7309189-3']);
			  _gaq.push(['_setDomainName', '.xivpads.com']);
			  _gaq.push(['_trackPageview']);

			  (function() {
				var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
				ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
				var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
			  })();

			</script>";
}

function findString($parentAnchor, $childAnchor, $startT, $endT, $file){
		$abort = false;
		$varDefStart = 1;
		if (!is_null($parentAnchor)){
			$varDefStart = strpos ($file, $parentAnchor);
			if ($varDefStart== False){
				$abort = true;
			}
		}
		if (!is_null($childAnchor)){
			$varDefStart = strpos ($file, $childAnchor, $varDefStart);
			if ($varDefStart== False){
				$abort = true;
			}
		}
		//if ($varDefStart >= 0 && $varDefStart<=strlen($file) && !($varDefStart==False)) {
			//echo "first anchor:".$varDefStart."<br>";
		$startPointRaw  = strpos  ($file, $startT, $varDefStart);
		if (($startPointRaw!= False) && ($abort == false)){
			$startPoint = $startPointRaw+strlen($startT);
			//echo "startpoint:".$startPoint."<br>";
			$endPoint = strpos  ($file, $endT, $startPoint);
			//echo "endpoint:".$endPoint."<br>";
			Return substr ($file, $startPoint, ($endPoint-($startPoint)));
		}else{
			Return "";
		}

}

function getCensoredSkills()
{
	
	return implode( ",", array(
				"22704"
				,"22705"
				,"22706"
				,"29043"
				,"29039"
				,"29041"
				,"29044"
				,"22707"
				,"22708"
				,"22709"
				,"22701"
				,"22702"
				,"22703"
				,"22112"
				,"28677"
				));
}


function getBaseURL(){

	return "http://beta.xivpads.com/?Specs";
}


?>